package com.ld.caodan.adapter;

import java.util.List;

import android.content.Context;
import android.text.Html;
import android.text.TextUtils.TruncateAt;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

import com.ld.caodan.activity.R;
import com.ld.caodan.common.ContentLoader;
import com.ld.caodan.common.ContentLoader.ContentCallBack;
import com.ld.caodan.entity.Article;
import com.ld.caodan.util.StringUtils;

/**
 * 
 * 
 * @author 刘笛 2011-11-2 上午10:19:21
 */
public class CDListAdapter extends BaseAdapter<Article> {

	ContentLoader contentLoader = null;
	ListView listView = null;

	public CDListAdapter(Context context, List<Article> list) {
		super(context, list);
		contentLoader = new ContentLoader();
	}
	public CDListAdapter(Context context, List<Article> list,ListView listView) {
		super(context, list);
		contentLoader = new ContentLoader();
		this.listView = listView;
	}

	@Override
	public View newView() {
		return  inflater.inflate(R.layout.textview4listview, null);
	}

	@Override
	public void bindDate2View(View view, final Article article) {
		TextView date = (TextView) view.findViewById(R.id.date);
		date.setText(article.getDate());
		TextView author = (TextView) view.findViewById(R.id.author);
		author.setText("作者:" + article.getAuthor());
		TextView column = (TextView) view.findViewById(R.id.column);
		column.setText("栏目:" + article.getColumn());
		final TextView contentView = (TextView) view.findViewById(R.id.content);
//		contentView.setEllipsize(TruncateAt.END);
		String link = article.getContentLink();
//		contentView.setTag(link);
//		Article newArticle = contentLoader.loadContent(link, new ContentCallBack() {
//			@Override
//			public void getContent(String url, String content) {
//				TextView textView = (TextView) listView.findViewWithTag(url);
//				if(textView!=null){
//					textView.setText(Html.fromHtml(content));
//					article.setContent(content);
//				}
//			}
//		});
//		String content = "";
//		if(newArticle!=null){
//			content = newArticle.getContent();
//			article.setDing(newArticle.getDing());
//			article.setCai(newArticle.getCai());
//		}
//		if(StringUtils.isBlank(content)){
//			contentView.setText("正在加载...");
//		}else{
//			contentView.setText(Html.fromHtml(content));
//			article.setContent(content);
//		}
		
//		if(Html.fromHtml(article.getContent())!=null){
//			String temp = Html.fromHtml(article.getContent()).toString();
//			if(temp.length()>70){
//				contentView.setText(temp.substring(0,70)+"。。。");
//			}else{
				contentView.setText(Html.fromHtml(article.getContent()));
//			}
//		}
	}

}
